<?php
/**
 * 用户操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * create by allen.qiang
 */
quanli_require('module/base/system/sysUser.class.php');
quanli_require('module/base/system/sysDepartment.class.php');

class pa_userList {

    public function execute() {


        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']) {

                case 1:
                    $this->init();
                    break;

                case 5: //个人设置
                    $this->personnel_set();
                    break;

                default:
                    $this->toError('参数错误');
                    break;
            }
        } else {
            $this->toError('参数错误');
        }
    }

    /**
     * 转跳到错误页面
     * @param string $msg 错误信息
     */
    private function toError($msg = '') {

        global $G_PGLOB;

        $G_PGLOB->display_error_page($msg);
    }

    //用户列表
    private function init() {

        global $G_PGLOB;

        $G_PGLOB->smarty->assign('edit_permission', $G_PGLOB->has_permission(8));
        
        //加载角色类
        quanli_require('module/base/system/sysRole.class.php');

         //实例角色类
        $sysRole = new sysRole($G_PGLOB->DBCA);
        
        $arg_array = array();
        $role_group_array = $sysRole->searchRoleGroup($arg_array);
        
        if (!$role_group_array) {
            $this->toError('角色组信息没有找到');
        }

       
        foreach ($role_group_array as &$group) {

            //查询角色信息
            $arg_array = array(
                'roleGroupID' => $group['roleGroupID']
            );
            $group['role_list'] = $sysRole->searchRole($arg_array);
            
        }
        if ($group == 0) {
            $this->toError('角色信息没有找到');
        }
        /**
         * =============================
         * 查询角色组及角色信息
         * =============================
         */
        $G_PGLOB->smarty->assign_by_ref('role_group_array', $role_group_array);
        //查询城市信息
        $city_array = get_city();
        $G_PGLOB->smarty->assign_by_ref('city_array', $city_array);
        
        //实例部门类
        $sysDepartment = new sysDepartment();
        //部门数据
        $department_array = array();

        //递归查询部门数据
        $sysDepartment->searchDepartment( $department_array );
        
        //生成部门下拉框html代码
        $department_select_html = '';
        $sysDepartment->createDepartmentSelectOptionHtml( $department_array, $department_select_html );
        $G_PGLOB->smarty->assign_by_ref('department_select_html', $department_select_html);
        
        $G_PGLOB->smarty->display('system/userList.tpl');
    }


    /**
     * 个人设置
     */
    private function personnel_set() {

        global $G_PGLOB;

        if (!$G_PGLOB->isUserLogon) {
            $this->toError('用户未登录');
        }

        //实例化后台用户类
        $sysUser = new sysUser($G_PGLOB->DBCA);

        //查询用户信息
        $arg_array = array(
            'userID' => $G_PGLOB->currentUserID
        );
        $user_array = $sysUser->searchUserInfo($arg_array);
        if (!$user_array) {
            $this->toError('用户信息没有找到');
        }

        $G_PGLOB->smarty->assign_by_ref('user_array', $user_array[0]);

        $G_PGLOB->smarty->display('system/user_personnel.tpl');
    }

}